package com.szpx.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.szpx.entity.Goods;
import com.szpx.entity.Page;
import com.szpx.mapper.GoodsMapper;
import com.szpx.service.GoodsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Wangtx
 * @version 1.0.0
 * @title GoodsServiceImpl
 * @create 2024/4/6 22:28
 * @description
 */
@Service
@Transactional
public class GoodsServiceImpl implements GoodsService {
    @Resource
    private GoodsMapper goodsMapper;

    /**
     * 浏览
     * @return
     */
    @Override
    public Page findAllGoodsPage(Integer pageNo, Integer pageSize, Integer id) {
        Page page=new Page();
        PageHelper.startPage(pageNo,pageSize);
        List<Goods> goods=goodsMapper.findAllGoods(id);
        PageInfo<Goods> info=new PageInfo<>(goods);
        page.setPage(info.getList());
        page.setPageNo(info.getPageNum());
        page.setPageSize(info.getPageSize());
        page.setHasNext(info.isHasNextPage());
        page.setHasPre(info.isHasPreviousPage());
        page.setPageCount(info.getPages());
        page.setTotal(info.getTotal());
        return page;
    }

    /**
     * 生成
     * @param goods
     */
    @Override
    public void addGoods(Goods goods){
        goodsMapper.addGoods(goods);
    }

    /**
     * 修改
     * @param goods
     */
    @Override
    public void updateGoods(Goods goods){
        goodsMapper.updateGoods(goods);
    }

    /**
     * 单个删除
     * @param id
     */
    @Override
    public void deleteGoodsByGoodsId(Integer id){
        goodsMapper.deleteGoodsByGoodsId(id);
    }

    /**
     * 批量删除
     * @param goodsIds
     */
    @Override
    public void deleteAllSelectGoods(List<Integer> goodsIds){

        goodsMapper.deleteAllSelectGoods(goodsIds);
    }

    /**
     * id查询运费总价
     * @param id
     * @return
     */
    @Override
    public Integer allFreightPrice(Integer id){
        Integer price =goodsMapper.allFreightPrice(id);
        return price;
    }//计算

    @Override
    public List<Goods> getGoodsList(){
        return goodsMapper.getGoodsList();
    }
}
